package com.tanhua.server.service;

import com.tanhua.domain.db.User;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class CachingTestService {

    /**
     * 需要缓存的方法
     */
    @Cacheable(cacheNames = "users", key = "#userId")
    public User findById(Long userId) {
        System.out.println("查询数据库...");
        User user = new User();
        user.setId(userId);
        user.setMobile("13900139000");
        return user;
    }

    /**
     * 需要清除缓存的方法
     */
    @CacheEvict(cacheNames = "users", key = "#userId")
    public void update(Long userId) {
        System.out.println("update...");
    }
}
